package com.liuyk.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.liuyk.main.activity.R;

import java.util.List;

/**
 * Desc
 * <p>
 * Created by liuyakui on 2020/11/30.
 */
public class NestedAdapter extends RecyclerView.Adapter<NestedAdapter.MyViewHolder> {
    private List<String> mItems;

    public void setItems(List<String> mItems) {
        this.mItems = mItems;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        Log.i("rvCreate", "onCreateViewHolder");
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.nested_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.nested_tv.setText(mItems.get(position));
    }

    @Override
    public int getItemCount() {
        return mItems != null ? mItems.size() : 0;
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView nested_tv;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            nested_tv = itemView.findViewById(R.id.nested_tv);
        }
    }
} 